package com.zzxy.controller;

import com.zzxy.entity.Newsperson;
import com.zzxy.service.NewspersonService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * (Newsperson)表控制层
 *
 * @author makejava
 * @since 2023-11-28 10:51:08
 */
@Controller
@RequestMapping("newsperson")
public class NewspersonController {
    /**
     * 服务对象
     */
    @Resource
    private NewspersonService newspersonService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Newsperson selectOne(Integer id) {
        return this.newspersonService.queryById(id);
    }

    @RequestMapping("test")
    public String test() {
        Newsperson newsperson = newspersonService.queryById(1);
        System.out.println(newsperson);
        return "/newsperson/test";
    }
@RequestMapping("/login")
private String login(String name, String password, HttpSession session, Model model) {
    Newsperson newsperson = newspersonService.login(name, password);
    if (newsperson != null) {
        session.setAttribute("loginNewsperson", newsperson);
        return "/newsperson/main";
    } else {
        model.addAttribute("msg", "账号或密码错误，请重新登录");
        return "/newsperson/login";
    }
}
}